package com.ruoyi.hotel.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.hotel.domain.HlDevice;
import com.ruoyi.hotel.service.IHlDeviceService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 酒店设备Controller
 * 
 * @author ruoyi
 * @date 2022-12-10
 */
@RestController
@RequestMapping("/hotel/hldevice")
public class HlDeviceController extends BaseController
{
    @Autowired
    private IHlDeviceService hlDeviceService;

    //git 测试

    /**
     * 查询酒店设备列表
     */
    @PreAuthorize("@ss.hasPermi('hotel:hldevice:list')")
    @GetMapping("/list")
    public TableDataInfo list(HlDevice hlDevice)
    {
        startPage();
        List<HlDevice> list = hlDeviceService.selectHlDeviceList(hlDevice);
        return getDataTable(list);
    }

    /**
     * 查询所有设备列表
     * 此处懒得在js那导入获取所有设备的uri来获取，直接在这里写吧
     */
    @PreAuthorize("@ss.hasPermi('hotel:hldevice:list')")
    @GetMapping("/devices")
    public List<HlDevice> selectAllDevice()
    {
        return hlDeviceService.selectAllDevice();
    }

    /**
     * 导出酒店设备列表
     */
    @PreAuthorize("@ss.hasPermi('hotel:hldevice:export')")
    @Log(title = "酒店设备", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, HlDevice hlDevice)
    {
        List<HlDevice> list = hlDeviceService.selectHlDeviceList(hlDevice);
        ExcelUtil<HlDevice> util = new ExcelUtil<HlDevice>(HlDevice.class);
        util.exportExcel(response, list, "酒店设备数据");
    }

    /**
     * 获取酒店设备详细信息
     */
    @PreAuthorize("@ss.hasPermi('hotel:hldevice:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(hlDeviceService.selectHlDeviceById(id));
    }

    /**
     * 新增酒店设备
     */
    @PreAuthorize("@ss.hasPermi('hotel:hldevice:add')")
    @Log(title = "酒店设备", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody HlDevice hlDevice)
    {
        return toAjax(hlDeviceService.insertHlDevice(hlDevice));
    }

    /**
     * 修改酒店设备
     */
    @PreAuthorize("@ss.hasPermi('hotel:hldevice:edit')")
    @Log(title = "酒店设备", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody HlDevice hlDevice)
    {
        return toAjax(hlDeviceService.updateHlDevice(hlDevice));
    }

    /**
     * 删除酒店设备
     */
    @PreAuthorize("@ss.hasPermi('hotel:hldevice:remove')")
    @Log(title = "酒店设备", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(hlDeviceService.deleteHlDeviceByIds(ids));
    }
}
